var http = require("http");
var fs = require("fs");
var urlParse = require("url").parse;


var urlInfo = urlParse("http://www.newxing.com/Code/download.asp?softid=608&downid=8&id=611");
var options = {
	method: "GET",
	host: urlInfo.hostname,
	port: 80,
	path: "Code/download.asp?softid=608&downid=8&id=611"
}

console.log(urlInfo.hostname + "   " + urlInfo.port + "   " + urlInfo.pathname);
console.log(urlInfo.search + "      " + urlInfo.protocol);

var request = http.request(options, function(response){
	var writeStream = fs.createWriteStream("test.rar");
	
	response.pipe(writeStream);
	
	request.on("end", function(){
            console.log("download status:", request.statusCode);

            if(request.statusCode == 200){
                console.log("download img file ok!");
                callback(null, true);
            } else {
                callback(null, false);
            }
        }).on("error", function(e){
            console.log("Got error: " + e.message);
            callback(null, false);
        });
});

setTimeout(request.end(), 1000*5);

